<?php
namespace Client\Controller;

use Zend\View\Model\ViewModel;

class MyCollectionController extends InitializeController
{   
	
	protected function  getOrgProductsRecommanded($orgList){
		$orgIds=array();//组织显示 id
		$orgRs=array();//组织推荐商品
		$recRs=array();//推荐商品信息
	
		foreach($orgList as $k=>$v){
			$orgIds[] = $v['org_id'];
			$orgRs[$v['org_id']]['data'] = $v;
			$orgRs[$v['org_id']]['recommended']=array("无");
		}
	
		$recommendedList=$this->getProductTable()->getOrgProductsRecommended($orgIds);
	
		foreach($recommendedList as $k=>$v){
			if(!empty($v['product_name'])){
				$recRs[$v['org_id']][] =$v['product_name'];
			}
		}
	
		foreach($orgRs as $k =>$v){
			if(!empty($recRs[$k])){
				$orgRs[$k]['recommended']=$recRs[$k];
			}
		}
		return $orgRs;
	}

	
    public function indexAction(){
    	
    	$orgList=array();//单位列表
    	$favorites=array();//收藏
    	$userId=$this->user_id?$this->user_id:123;
    	$query=array('user_id'=>$userId);
    	$orgList=$this->getFavoritesTable()->getMyFavorites($query);
    	if(!empty($orgList)){
    		$favorites =$this->getOrgProductsRecommanded($orgList);
    	}
    	return new ViewModel(array(
    		'favorites' => $favorites
    	));

    }
  
}